<?
include_once 'functions.php';
$dbh=dbConn();

$id = null;

if(!isset($_GET['id']))
{ echo mysql_error(); }
else
{
	$id = $_GET['id'];

	$sql = "SELECT picture, picture_type, picture_size, picture_name FROM companies WHERE id=$id";
		
	$result = mysql_query($sql, $dbh);
	$size	= mysql_result($result, 0, "picture_size");
	
	$data = "";

	if($size == 0)
	{
		header("Content-type: image/jpeg");
		
		$fileName = "images/NoPhotoAvailable.jpg";
		
		$fp 	= fopen($fileName,"r");
		
		$data 	= fread($fp, filesize($fileName));
		
		fclose($fp);
	}
	else
	{
		$data 	= mysql_result($result, 0, "picture");
		$type 	= mysql_result($result, 0, "picture_type");
	
		header("Content-type: $type");
	}

	print $data;

	dbClose($dbh);

	exit;

}

?>
